from math import *
a = int(input("Введите четырехзначное число"))

if 999 < a < 10000:
    d = a // 1000
    f = a % 1000 // 100
    g = a % 100 // 10 
    h = a % 10 
    q = d + f
    w = d + f + g
    e = d + f + g + h
    r = f + g 
    t = f + g + h 
    y = g + h 

    k = 0 
    for i in range(2, (d//2)+1):
        if d % i == 0:
            k+=1
    if k <= 0:
      prime = True
    else:
        d = 0
    
    for i in range(2, (f//2)+1):
        if f % i == 0:
            k+=1
    if k <= 0:
       prime = True
    else:
        f = 0
    
         
         
    for i in range(2, (g//2)+1):
        if g % i == 0:
            k+=1
    if k <= 0:
        prime = True
    else:
        g = 0
    
         
    
    for i in range(2, (h//2)+1):
        if h % i == 0:
            k+=1
    if k <= 0:
         prime = True
    else:
        h = 0
   
        
    
    for i in range(2, (q//2)+1):
        if q % i == 0:
            k+=1
    if k <= 0:
          prime = True
    else:
        q = 0
    
       
    
    for i in range(2, (w//2)+1):
        if w % i == 0:
            k+=1
    if k <= 0:
         prime = True
    else:
        w = 0
    
    for i in range(2, (e//2)+1):
        if e % i == 0:
            k+=1
    if k <= 0:
         prime = True
    else:
        e = 0
    
    for i in range(2, (r//2)+1):
        if r % i == 0:
            k+=1
    if k <= 0:
        prime = True
    else:
        r = 0
    
    for i in range(2, (t//2)+1):
        if t % i == 0:
            k+=1
    if k <= 0:
         prime = True
    else:
        t = 0
    
    for i in range(2, (y//2)+1):
        if y % i == 0:
            k+=1
    if k <= 0:
        prime = True
    else:
        y = 0
         
    z = max(d, f, g, h, q, w, e, r, t, y)
    print(z)

else:
    print("0")
